import { mapGetters, mapState } from "vuex";
import { getPlcSignal } from "@/api/assembly/cage";
import { handerCmd } from "@/api/assembly/cage"
export default {
    data() {
        return {
            timer: null
        };
    },
    created() {
        clearInterval(this.timer)
    },
    mounted() {

    },

    methods: {
        // 开启定时器 循环调用获取设备状态，和plc 信号
        getSignal(params) {
            clearInterval(this.timer)
            params && this.$store.dispatch("getDeviceSignal", params)
            this.device != null && this.getDeviceSignal()
            this.timer = setInterval(() => {
                params && this.$store.dispatch("getDeviceSignal", params)
                this.device != null && this.getDeviceSignal()
            }, 7000)
        },
        // 获取 cmdList 
        getDeviceSignal() {
            let params = {
                dictValue: this.device.dictValue instanceof Array ? this.device.dictValue[this.subClickCard] : this.device.dictValue,
            };
            getPlcSignal(params).then((res) => {
                this.tableData = res.data;
            });
        },
        // 处理cmd 命令 返回、补发、完成信号
        handlerCmd(e, item) {
            this.$prompt("请输入密码", "提示", {
                confirmButtonText: "确定",
                cancelButtonText: "取消",
                inputPattern: /^8863$/,
                inputErrorMessage: "密码错误",
                
            })
                .then(({ value }) => {
                    let newData = Object.assign(item, { handleType: e })
                    handerCmd(newData).then((res) => {
                        this.$message.success("执行成功")
                    })
                })



        }
    },
    destroyed() {
        // 清除定时器
        clearInterval(this.timer)
    },
    computed: {
        ...mapState({
            // 获取设备plc各种状态值
            deviceList: (state) => {
                return state.deviceStatus.deviceList || []
            }
        })
    },
};